home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 1 / PC Actual CD 01.iso / f1 / cimb.arj / PSCRIPT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-03  |  4.6 KB  |  186 lines

  1. /*==============================================================================
  2.  
  3. FICHERO: PSCRIPT.C
  4.  
  5. AUTOR: ANTONIO LADESA JURADO
  6.  
  7. FECHA: 24/6/94
  8.  
  9. DESCRIPCION:
  10.  
  11.     Fichero que contiene las estructuras, constantes, variables y funciones
  12.     internas y externas para la impresión de las imágenes en lenguaje PostScript.
  13.  
  14. ==============================================================================*/
  15.  
  16.  
  17. /*---- MODULOS USADOS --------------------------------------------------------*/
  18.  
  19. #include <stdio.h>
  20. #include <conio.h>
  21. #include <dos.h>
  22. #include <string.h>
  23.  
  24. #include "global.h"
  25. #include "memoria.h"
  26. #include "video.h"
  27. #include "pscript.h"
  28. #include "color.h"
  29. #include "error.h"
  30.  
  31. /*---- DEFINICION DE LAS FUNCIONES INTERNAS ----------------------------------*/
  32.  
  33.  
  34. void POSTSCRIPTescribirCodigo(IMAGEN *c,FILE *f);
  35.  
  36.  
  37. /*---- CODIFICACION DE LAS FUNCIONES OFRECIDAS -------------------------------*/
  38.  
  39.  
  40. /*---- FUNCION: extern int POSTSCRIPTimprimir(IMAGEN *c,char *nombre) ----------
  41.  
  42.     Descripción:
  43.  
  44.         Esta función envía una imagen en lenguaje PostScript a la impresora o
  45.         a un fichero.
  46.  
  47.     Parámetros:
  48.  
  49.         IMAGEN *c : puntero a estructura que alberga la imagen
  50.         char *nombre : nombre del fichero de salida (o cte = "IMPRESORA")
  51.  
  52.     Retorno:
  53.  
  54.         - 1 si hubo éxito.
  55.         - 0 si hubo error.
  56.  
  57. ---- CODIGO: -----------------------------------------------------------------*/
  58.  
  59. extern int POSTSCRIPTimprimir(IMAGEN *c,char *nombre)
  60. {
  61.     /* puntero al fichero */
  62. FILE *f;
  63.     /* puntero a la imagen duplicada */
  64. IMAGEN *r = NULL;
  65.  
  66.     /* si no hay imagen, error */
  67. if(c==NULL)
  68.     {
  69.     ERRORponer(ERRnoImagen);
  70.     return(0);
  71.     }
  72.     /* duplicar la imagen para transformarla */
  73. if((r = IMAGENduplicar(c))==NULL)
  74.     {
  75.     ERRORponer(ERRnoMemoria);
  76.     return(0);
  77.     }
  78.  
  79.     /* adaptar el modo de vídeo */
  80. if(r->modo == VIDEOega)
  81.     r = VIDEOvision(r);
  82.  
  83.     /* si el destino es el disco */
  84. if(strcmp(nombre,"IMPRESORA"))
  85.     {
  86.         /* abrir el fichero */
  87.     if((f = fopen(nombre, "wb")) == NULL)
  88.         {
  89.         ERRORponer(ERRapertura);
  90.         r = MEMliberar(r);
  91.         return(0);
  92.         }
  93.         /* escribir la imagen POSTSCRIPT */
  94.     POSTSCRIPTescribirCodigo(r,f);
  95.         /* cerrar el fichero */
  96.     fclose(f);
  97.     }
  98. else
  99.         /* si es la impresora, imprimir */
  100.     POSTSCRIPTescribirCodigo(r,stdprn);
  101.     /* liberar imagen duplicada */
  102. r=MEMliberar(r);
  103. return(1);
  104. }
  105.  
  106. /*---- FIN FUNCION -----------------------------------------------------------*/
  107.  
  108.  
  109. /*---- CODIFICACION DE LAS FUNCIONES INTERNAS --------------------------------*/
  110.  
  111.  
  112. /*---- FUNCION: void POSTSCRIPTescribirCodigo(IMAGEN *c,FILE *f) ---------------
  113.  
  114.     Descripción:
  115.  
  116.         Esta función escribe en el fichero o impresora las ordenes PostScript
  117.         para imprimir la imagen
  118.  
  119.     Parámetros:
  120.  
  121.         IMAGEN *c : puntero a la estructura que alberga la imagen
  122.         FILE *f : puntero al fichero ( o a stdprn)
  123.  
  124. ---- CODIGO: -----------------------------------------------------------------*/
  125.  
  126. void POSTSCRIPTescribirCodigo(IMAGEN *c,FILE *f)
  127. {
  128.     /* buffer */
  129. char p[ANCHO_MAXIMO];
  130.     /* contadores */
  131. int i,j;
  132.     /* valores a modificar según el modo de vídeo */
  133. int ancho,alto,bits,ppp;
  134.  
  135.     /* adecuar dimensiones y número de bits por pixel según el modo de vídeo */
  136. switch(c->modo)
  137.     {
  138.     case VIDEOmono:
  139.         ppp = 640;
  140.         ancho = (640/ppp)*(c->ancho/8);
  141.         alto = (640/ppp)*(c->alto/8);
  142.         bits = 1;
  143.     break;
  144.     case VIDEOvga:
  145.         c = PonerGris(c);
  146.         ppp = 96;
  147.         ancho = (int)((double)c->ancho*0.75);
  148.         alto = (int)((double)c->alto*0.75);
  149.         bits = 8;
  150.     break;
  151.     };
  152.  
  153.     /* código postscript */
  154. fprintf(f,"%%!PS_Adobe-2.0\r\n");
  155. fprintf(f,"%%%%BoundingBox: 0 0 %u %u\r\n",ancho,alto);
  156. fprintf(f,"%%%%Creator: CIMB. Antonio Ladesa.\r\n");
  157. fprintf(f,"%%%%Title: %s\r\n",c->nombre);
  158. fprintf(f,"/width %u deftity: %u %u %u 1 %u %u 1\r\n",
  159.                 c->ancho,c->ancho,c->alto,bits,ppp,c->bytes);
  160. fprintf(f,"/height %u def\r\n",c->alto);
  161. fprintf(f,"/glevel %u def\r\n",bits);
  162. fprintf(f,"/dpi %u def\r\n",ppp);
  163. fprintf(f,"/istr %u string def\r\n",c->ancho);
  164. fprintf(f,"/nheight height neg def\r\n");
  165. fprintf(f,"/imageturkeypi div mul } def\r\n");
  166. fprintf(f,"{ width height glevel [width 0 0 nheight 0 height]\r\n");
  167. fprintf(f,"  { currentfile istr readhexstring pop } image\r\n");
  168. fprintf(f,"} def\r\n");
  169. fprintf(f,"gsave\r\n");
  170. fprintf(f,"0 0 translate\r\n");
  171. fprintf(f,"width dot height dot scale\r\n");
  172. fprintf(f,"imageturkey\r\n");
  173.  
  174.     /* datos de la imagen */
  175. for(i=0;i<c->alto;++i)
  176.     {
  177.     MEMleer(p,i,c);
  178.     for(j=0;j<c->ancho;++j)
  179.         fprintf(f,"%02.2X",p[j]);
  180.     fprintf(f,"\r\n");
  181.     }
  182. fprintf(f,"grestore\r\n");
  183. fprintf(f,"showpage\r\n");
  184. }
  185.  
  186. /*---- FIN FUNCION -----------------------------------------------------------*/